//package com.mask.sca.auth.security;
//
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//
//@Component("TenantFilterV2")
//@ConditionalOnProperty(prefix = "mask.tenant", name = "enabled", havingValue = "true", matchIfMissing = true)
//public class TenantFilter implements Filter {
//    private static final String TENANT_HEADER = "X-Tenant-Id";
//
//    @Override
//    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//        HttpServletRequest httpRequest = (HttpServletRequest) request;
//        String path = httpRequest.getRequestURI();
//        // 放行token相关接口
//        if (path.startsWith("/oauth/token") || path.startsWith("/oauth/") || path.startsWith("/auth/login")) {
//            chain.doFilter(request, response);
//            return;
//        }
//        String tenantId = httpRequest.getHeader(TENANT_HEADER);
//        if (tenantId != null) {
//            TenantContext.setTenantId(tenantId);
//        }
//        try {
//            chain.doFilter(request, response);
//        } finally {
//            TenantContext.clear();
//        }
//    }
//}